#include "widget.h"
#include "ui_widget.h"

#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    // 创建垂直的布局管理器
    QVBoxLayout* vlayout = new QVBoxLayout();
    this->setLayout(vlayout);
    // 添加按钮
    QPushButton* but1 = new QPushButton("按钮1");
    QPushButton* but2 = new QPushButton("按钮2");
    vlayout->addWidget(but1); vlayout->addWidget(but2);

    // 创建水平的布局管理器
    QHBoxLayout* hlayout = new QHBoxLayout();
    QPushButton* but3 = new QPushButton("按钮3");
    QPushButton* but4 = new QPushButton("按钮4");
    hlayout->addWidget(but3); hlayout->addWidget(but4);

    // 把水平布局管理器添加到垂直布局管理器器内部
    vlayout->addLayout(hlayout);
}

Widget::~Widget()
{
    delete ui;
}

